package com.naiterui.common.jinshuju.api;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.naiterui.common.jinshuju.bean.JinshujuCallback;
import com.naiterui.common.jinshuju.exception.JinshujuException;
import com.naiterui.common.jinshuju.service.JinshujuClientService;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * 金数据API
 */
@Slf4j
@RestController
@RequestMapping("jinshuju")
@RequiredArgsConstructor
public class JinshujuApi {

    @Autowired
    private final JinshujuClientService jinshujuClientService;

    /**
     * 金数据回执回调
     */
    @PostMapping("{uid}/callback")
    public String handleCallback(@PathVariable String uid, @RequestBody JinshujuCallback jinshujuCallback) throws JinshujuException {
        log.debug("金数据回调 uid:{} jinshujuCallback:{}", uid, jinshujuCallback);
        jinshujuClientService.handleCallback(uid, jinshujuCallback);
        return "SUCCESS";

    }

}
